package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppArticle;
import com.ruoyi.system.service.ISysAppArticleService;

/**
 * 经方文章Controller
 * 
 * @author ruoyi
 * @date 2020-08-16
 */
@Controller
@RequestMapping("/system/article")
public class SysAppArticleController extends BaseController {
	private String prefix = "system/article";

	@Autowired
	private ISysAppArticleService sysAppArticleService;

	@RequiresPermissions("system:article:view")
	@GetMapping()
	public String article() {
		return prefix + "/article";
	}

	/**
	 * 查询经方文章列表
	 */
	@RequiresPermissions("system:article:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppArticle sysAppArticle) {
		startPage();
		List<SysAppArticle> list = sysAppArticleService.selectSysAppArticleList(sysAppArticle);
		return getDataTable(list);
	}

	/**
	 * 导出经方文章列表
	 */
	@RequiresPermissions("system:article:export")
	@Log(title = "经方文章", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppArticle sysAppArticle) {
		List<SysAppArticle> list = sysAppArticleService.selectSysAppArticleList(sysAppArticle);
		ExcelUtil<SysAppArticle> util = new ExcelUtil<SysAppArticle>(SysAppArticle.class);
		return util.exportExcel(list, "article");
	}

	/**
	 * 新增经方文章
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存经方文章
	 */
	@RequiresPermissions("system:article:add")
	@Log(title = "经方文章", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppArticle sysAppArticle) {
		return toAjax(sysAppArticleService.insertSysAppArticle(sysAppArticle));
	}

	/**
	 * 修改经方文章
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppArticle sysAppArticle = sysAppArticleService.selectSysAppArticleById(id);
		mmap.put("sysAppArticle", sysAppArticle);
		return prefix + "/edit";
	}
	

	/**
	 * 修改保存经方文章
	 */
	@RequiresPermissions("system:article:edit")
	@Log(title = "经方文章", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppArticle sysAppArticle) {
		return toAjax(sysAppArticleService.updateSysAppArticle(sysAppArticle));
	}

	/**
	 * 删除经方文章
	 */
	@RequiresPermissions("system:article:remove")
	@Log(title = "经方文章", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppArticleService.deleteSysAppArticleByIds(ids));
	}
}
